package com.unbox.rabbit.comfig;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * rabbit 配置文件
 */
@Configuration
public class RabbitConfig {

    // log 日志收集
    public static final String LOG_QUEUE_NAME = "log_queue";
    public static final String LOG_EXCHANGE = "log_queueExchange";

    /**
     * 创建队列
     * @return
     */
    @Bean
    public Queue createLogQueue() {
        return new Queue(LOG_QUEUE_NAME);
    }

    /**
     * 创建交换机
     * @return
     */
    @Bean
    public FanoutExchange createlogExchange() {
        return new FanoutExchange(LOG_EXCHANGE);
    }

    /**
     * 队列绑定交换机
     * @return
     */
    @Bean
    Binding bindingFanout() {
        return BindingBuilder.bind(createLogQueue()).
                to(createlogExchange());
    }
}
